<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User_man_model extends CI_Model {

	function __construct()
	{
		parent::__construct();
		$this->CI = get_instance();
	}
	
	function insert_user($data){
		$this->db->insert('HD_USER',$data);
	}
	
	function get_user_man_grid(){	
		$this->db->select('*');
		$this->db->from('HD_USER');
		//$this->db->join('ROLE','ROLE.IDROLE = HD_USER.IDROLE');
		//$this->db->where("HD_USER.AKTIV > 0 ");
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('*');
		$this->db->from('HD_USER');
		//$this->db->join('ROLE','ROLE.IDROLE = HD_USER.IDROLE');
		//$this->db->where("HD_USER.AKTIV > 0 ");
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	
	function delete_user($id_user){
		$this->db->where('USERNAME',$id_user);
		$this->db->delete('HD_USER');
	}
	
	function get_userID($id_user){
		$this->db->select('*');
		$this->db->from('HD_USER');
		$this->db->where('USERNAME',$id_user);
		$query = $this->db->get();
		return $query;
	}
	
	function get_all_bagian(){
		$this->db->select("*");
		$this->db->from('V_BAGIAN');
		$query = $this->db->get();
		return $query;
	}

	function get_bagian($id_bagian){
		$this->db->select("*");
		$this->db->from('V_BAGIAN');
		$this->db->where('KODE_UNIT_KERJA',$id_bagian);
		$query = $this->db->get();
		return $query;
	}
	
	function update_user($data,$id_user){
		$this->db->where('IDUSER',$id_user);
		$this->db->update('HD_USER',$data);
	}
	
	function get_user($username){
		$this->db->select("*");
		$this->db->from('HD_USER');
		//$this->db->where("AKTIV > 0 ");
		//$this->db->join('HD_PEGAWAI','KODE = USERNAME');
		$this->db->where('USERNAME',$username);
		$query = $this->db->get();
		return $query;
	}
	
}

?>